﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace ExamSharedClasses {
    /// <summary>
    /// (k) Der Fragentyp, der mehrere Antwortmöglichkeiten anbietet und bei
    /// dem nur eine Anwort richtig sein können. Die Wahl wird dabei
    /// bitweise (für jede Antwortmöglichkeit) in einem Integer gehalten.
    /// </summary>
    [Serializable()]
    public class QuestionTypeSingleMultiple : Question {
        new public const string TABLENAME = "question_type_single_multiple";
        public const string QUESTION_AUTHOR = "question_autor";
        public const string QUESTION_BODY = "question_body";
        public const string QUESTION_ANSWER1 = "question_answer_1";
        public const string QUESTION_ANSWER2 = "question_answer_2";
        public const string QUESTION_ANSWER3 = "question_answer_3";
        public const string QUESTION_ANSWER4 = "question_answer_4";
        public const string QUESTION_RIGHT_ANSWER = "question_right_answer";
        public const string QUESTION_ACTIVE = "question_active";

        public User QuestionAuthor { get; set; }
        public string QuestionBody { get; set; }
        public string QuestionAnswer1 { get; set; }
        public string QuestionAnswer2 { get; set; }
        public string QuestionAnswer3 { get; set; }
        public string QuestionAnswer4 { get; set; }
        public int QuestionRightAnswer { get; set; }
        public bool QuestionActive { get; set; }

        public QuestionTypeSingleMultiple()
            : base( ) {
                QuestionTypeObject = "single_multiple";
            QuestionAuthor = new User();
            QuestionBody = "";
            QuestionAnswer1 = "";
            QuestionAnswer2 = "";
            QuestionAnswer3 = "";
            QuestionAnswer4 = "";
            QuestionRightAnswer = -1;
            QuestionActive = true;
        }
        public QuestionTypeSingleMultiple( Question question )
            : base( question ) {
                QuestionTypeObject = "single_multiple";
            QuestionAuthor = new User();
            QuestionBody = "";
            QuestionAnswer1 = "";
            QuestionAnswer2 = "";
            QuestionAnswer3 = "";
            QuestionAnswer4 = "";
            QuestionRightAnswer = -1;
            QuestionActive = true;
        }

        public override string ToString() {
            StringBuilder sb = new StringBuilder( base.ToString() );
            sb.Append( "Author: " + QuestionAuthor.UserEmail + ")\n" );
            sb.Append( "Frage: " + QuestionBody.ToString() + '\n' );
            sb.Append( "Antwort 1: " + QuestionAnswer1.ToString() + '\n' );
            sb.Append( "Antwort 2: " + QuestionAnswer2.ToString() + '\n' );
            if ( QuestionAnswer3 != null )
                sb.Append( "Antwort 3: " + QuestionAnswer3.ToString() + '\n' );
            if ( QuestionAnswer4 != null )
                sb.Append( "Antwort 4: " + QuestionAnswer4.ToString() + '\n' );
            //besser nicht...sb.Append( "richtige Antwort: " + Tools.EnumerateLeftToRightPositionsOfPowersOfTwo( QuestionRightAnswer ) + '\n' );
            return sb.ToString();
        }

        public override string ToMoreDetailedString() {
            StringBuilder sb = new StringBuilder( );
            sb.Append( "richtige Antwort(en): " + Tools.EnumerateLeftToRightPositionsOfPowersOfTwo( QuestionRightAnswer ) + '\n' );
            sb.Append( "im Umlauf?: " + QuestionActive.ToString() + '\n' );
            return ToString() + sb.ToString();
        }

    }
}